import {
  checkImage,
  checkLongitude,
  checkLatitude,
  checkPhone,
  checkUserCode,
  checkName,
} from "./rules";
import ActionTypes from "../action";
import { dateFormat } from "@/util/date";
import { PromiseAuditMerchant } from "@/api/config";
import orderForm from "../orderForm";
const MerchantDetail = [
  {
    type: "text",
    prop: "merchantName",
    label: "姓名",
    placeholder: "请输入姓名",
    rule: [
      {
        required: true,
        validator: checkName,
        trigger: ["blur", "change"],
      },
      {
        max: 10,
        message: "姓名不能超过10个字",
        trigger: "change",
      },
    ],
  },
  {
    type: "number",
    prop: "mobile",
    label: "手机号",
    placeholder: "请输入手机号码",
    rule: {
      required: true,
      validator: checkPhone,
      trigger: ["blur", "change"],
    },
  },
  {
    type: "password",
    prop: "${password}",
    label: "密码",
    check_value() {
      return "";
    },
    show(_, type) {
      return type !== "view";
    },
    ruleOnAdd: [
      {
        required: true,
        message: "请输入密码",
        trigger: "blur",
      },
    ],
  },
  {
    type: "text",
    prop: "idCode",
    label: "身份证",
    placeholder: "请输入身份证",
    rule: {
      required: true,
      validator: checkUserCode,
      trigger: "change",
    },
  },
  {
    type: "text",
    prop: "longitude",
    label: "经度",
    show(_, type) {
      return type !== "view";
    },
    placeholder: "请输入经度数值",
    rule: [
      {
        required: true,
        message: "经度不能为空",
        trigger: "blur",
      },
      {
        validator: checkLongitude,
        trigger: ["blur", "change"],
      },
    ],
  },
  {
    type: "text",
    prop: "latitude",
    label: "纬度",
    show(_, type) {
      return type !== "view";
    },
    placeholder: "请输入纬度数值",
    rule: [
      {
        required: true,
        message: "纬度不能为空",
        trigger: "blur",
      },
      {
        validator: checkLatitude,
        trigger: ["blur", "change"],
      },
    ],
  },
  {
    type: "select",
    label: "省份",
    prop: "provinceCode",
    cascader: "cityCode",
    placeholder: "请选择省份",
    view(data) {
      return data.province;
    },
    option(_, $store) {
      return $store.getters["dic/province"];
    },
    auto_dispatch: "dic/getCityDic",
    rule: {
      required: true,
      message: "省份不能为空",
      trigger: "blur",
    },
  },
  {
    type: "select",
    label: "城市",
    prop: "cityCode",
    cascader: "districtCode",
    placeholder: "请选择城市",
    view(data) {
      return data.city;
    },
    option(_, $store) {
      return $store.getters["dic/city"];
    },
    dispatch: "dic/getCity",
    rule: {
      required: true,
      message: "城市不能为空",
      trigger: "blur",
    },
  },
  {
    type: "select",
    label: "县/地区",
    prop: "districtCode",
    placeholder: "请选择县/地区",
    dispatch: "dic/getDistrict",
    view(data, $store) {
      return (
        data.district ||
        ($store.getters["dic/cityCodMap"][data.districtCode] &&
          $store.getters["dic/cityCodMap"][data.districtCode].value) ||
        data.districtCode
      );
    },
    option(_, $store) {
      return $store.getters["dic/district"];
    },
    rule: {
      required: true,
      message: "县/地区不能为空",
      trigger: "blur",
    },
  },
  {
    type: "textarea",
    label: "详细地址",
    prop: "address",
    placeholder: "请输入详细地址",
    rule: {
      required: true,
      message: "详细地址不能为空",
      trigger: "blur",
    },
    maxLength: 120,
  },
  {
    type: "checkbox",
    label: "一级商品分类",
    prop: "${firstList}",
    auto_dispatch: "dic/getFirstCategoryList",
    check_type: "one",
    check_value(value = []) {
      return value.map((item) => {
        return {
          id: item.categoryId,
        };
      });
    },
    cascader: "${childList}",
    option(_, $store) {
      return $store.getters["dic/firstCategoryList"];
    },
    rule: [
      {
        required: true,
        message: "请选择至少一个分类",
        trigger: "change",
      },
    ],
  },
  {
    type: "checkbox",
    label: "二级商品分类",
    prop: "${childList}",
    dispatch: "dic/getSecondCategoryList",
    check_type: "two",
    option(_, $store) {
      return $store.getters["dic/secondCategoryList"];
    },
    check_value(value = []) {
      return value.map((item) => {
        return {
          id: item.categoryId,
        };
      });
    },
    rule: [
      {
        required: true,
        message: "请选择至少一个分类",
        trigger: "change",
      },
    ],
  },
  {
    type: "image",
    label: "个人形象照",
    prop: "visualizeUrl",
    upKey: "visualizeFileKey",
    rule: [
      {
        required: true,
        validator: checkImage,
        trigger: "change",
      },
    ],
  },
  {
    type: "image",
    label: "身份证正面",
    prop: "idFrontUrl",
    upKey: "idFrontFileKey",
    rule: [
      {
        required: true,
        validator: checkImage,
        trigger: "change",
      },
    ],
  },
  {
    type: "image",
    label: "身份证反面",
    prop: "idContraryUrl",
    upKey: "idContraryFileKey",
    rule: [
      {
        required: true,
        validator: checkImage,
        trigger: "change",
      },
    ],
  },
  {
    type: "image",
    label: "营业执照",
    prop: "businessLicenseUrl",
    upKey: "businessLicenseFileKey",
    rule: [
      {
        required: true,
        validator: checkImage,
        trigger: "change",
      },
    ],
  },
];
export default {
  [ActionTypes.MERCHANT_LIST]: {
    title: "商户",
    form: MerchantDetail,
  },
  [ActionTypes.MERCHANT_COMMENT_LIST]: {
    title: "订单详情",
    form: orderForm,
  },
  [ActionTypes.MERCHANT_AUDIT_LIST]: {
    title: "商户审批",
    form: MerchantDetail,
    viewFooter: {
      leftBtnText: "拒绝",
      leftBtn: "danger",
      rightBtnText: "通过",
      rightBtn: "primary",
      leftAction: [PromiseAuditMerchant, "NOT_PASS", "已拒绝该商户审批"],
      rightAction: [PromiseAuditMerchant, "PASS", "已通过该商户审批"],
    },
  },
  [ActionTypes.COUPON_MANAGE]: {
    title: "优惠券",
    form: [
      {
        type: "image",
        label: "商品图片",
        prop: "pictureUrl",
        upKey: "pictureFileKey",
        repeat: true,
      },
      {
        type: "text",
        label: "商品名称",
        prop: "productName",
      },
      {
        type: "text",
        label: "商品规格",
        prop: "specification",
      },
      {
        type: "text",
        label: "商品编号",
        prop: "productCode",
      },
      {
        type: "text",
        label: "数量",
        prop: "num",
      },
      {
        type: "text",
        label: "订单金额",
        prop: "orderFee",
      },
      {
        type: "text",
        label: "下单时间",
        prop: "gmtCreated",
      },
      {
        type: "text",
        label: "用户",
        prop: "nickName",
      },
      {
        type: "text",
        label: "用户电话",
        prop: "userMobile",
      },
      {
        type: "text",
        label: "收货地址",
        prop: "userAddress",
      },
      {
        type: "text",
        label: "租供日期",
        prop: "endTime",
        show(data) {
          return data.orderType === "LEASE";
        },
        view(data) {
          return `${dateFormat(data.startTime, "yyyy-mm-dd")}--${dateFormat(
            data.endTime,
            "yyyy-mm-dd"
          )}`;
        },
      },
      {
        type: "text",
        label: "优惠信息",
        prop: "fullMoney",
        view(data) {
          return `满${data.fullMoney}减${data.discounts}`;
        },
      },
      {
        type: "text",
        label: "实付金额",
        prop: "practical",
      },
      {
        type: "text",
        label: "商家姓名",
        topLine: true,
        prop: "merchantName",
      },
      {
        type: "text",
        label: "商家电话",
        prop: "mobile",
      },
      {
        type: "text",
        label: "店铺地址",
        prop: "address",
      },
      {
        type: "rate",
        label: "评价",
        prop: "starNum",
        topLine: true,
        show(data) {
          return ![null, undefined].includes(data.starNum);
        },
      },
      {
        type: "text",
        label: "评价内容",
        prop: "body",
        show(data) {
          return ![null, undefined].includes(data.starNum);
        },
      },
    ],
  },
};
